//
//  ZMyOrderDetailAddressInfoCell.m
//  DistributorAB
//
//  Created by LZY on 2019/10/14.
//  Copyright © 2019 主事丫环. All rights reserved.
//

#import "ZMyOrderDetailAddressInfoCell.h"
@interface ZMyOrderDetailAddressInfoCell ()
@property (nonatomic, strong) UILabel *lblDate;//下单时间
@property (nonatomic, strong) UILabel *lblName;//收货人姓名
@property (nonatomic, strong) UILabel *lblPhone;//收货人手机号
@property (nonatomic, strong) UILabel *lblAddress;//收货人地址
@end

@implementation ZMyOrderDetailAddressInfoCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self setupViewAction];
    }
    return self;
}
#pragma mark - 界面布局
- (void)setupViewAction{
    UILabel *lblNoticeDate = [[UILabel alloc] initWithFrame:CGRectMake(16, 10, 60, 20)];
    lblNoticeDate.text = @"下单时间";
    lblNoticeDate.font = [UIFont systemFontOfSize:14];
    lblNoticeDate.textColor = kColorWithHex(0x666666);
    [self.contentView addSubview:lblNoticeDate];
    
    _lblDate = [[UILabel alloc] initWithFrame:CGRectMake(106, 10, kScreen_Width - 122, 20)];
    _lblDate.font = [UIFont systemFontOfSize:12];
    _lblDate.textColor = kColorWithHex(0x999999);
    [self.contentView addSubview:_lblDate];
    
    UIView *viewLineOne = [[UIView alloc] initWithFrame:CGRectMake(16, 35, kScreen_Width - 16, 1)];
    viewLineOne.backgroundColor = kColorWithHex(0xf2f2f2);
    [self.contentView addSubview:viewLineOne];
    
    UILabel *lblNoticeAddress = [[UILabel alloc] initWithFrame:CGRectMake(16, 61, 70, 21)];
    lblNoticeAddress.text = @"收货地址";
    lblNoticeAddress.font = [UIFont systemFontOfSize:16];
    lblNoticeAddress.textColor = kColorWithHex(0x666666);
    [self.contentView addSubview:lblNoticeAddress];
    
    _lblName = [UILabel new];
    _lblName.font = [UIFont systemFontOfSize:14];
    _lblName.textColor = kColorWithHex(0x272727);
    _lblName.textAlignment = NSTextAlignmentLeft;
    [self.contentView addSubview:_lblName];
    [_lblName mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(viewLineOne.mas_bottom).offset(7);
        make.leading.equalTo(self.contentView.mas_leading).offset(106);
        make.height.mas_equalTo(20);
    }];
    
    _lblPhone = [UILabel new];
    _lblPhone.font = [UIFont systemFontOfSize:14];
    _lblPhone.textColor = kColorWithHex(0x272727);
    _lblPhone.textAlignment = NSTextAlignmentRight;
    [self.contentView addSubview:_lblPhone];
    [_lblPhone mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.lblName.mas_centerY);
        make.height.mas_equalTo(20);
        make.trailing.equalTo(self.contentView.mas_trailing).offset(-16);
    }];
    
    _lblAddress = [UILabel new];
    _lblAddress.font = [UIFont systemFontOfSize:14];
    _lblAddress.textColor = kColorWithHex(0x272727);
    _lblAddress.preferredMaxLayoutWidth = kScreen_Width - 128;
    _lblAddress.numberOfLines = 0;
    [self.contentView addSubview:_lblAddress];
    [_lblAddress mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.equalTo(self.lblName.mas_leading);
        make.top.equalTo(self.lblName.mas_bottom).offset(4);
        make.trailing.equalTo(self.contentView.mas_trailing).offset(-22);
        make.height.mas_greaterThanOrEqualTo(14);
    }];
    
    UIView *viewLineTwo = [UIView new];
    viewLineTwo.backgroundColor = kColorWithHex(0xf2f2f2);
    [self.contentView addSubview:viewLineTwo];
    [viewLineTwo mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView.mas_left);
        make.top.equalTo(self.lblAddress.mas_bottom).offset(10);
        make.right.equalTo(self.contentView.mas_right);
        make.bottom.equalTo(self.contentView.mas_bottom);
        make.height.mas_equalTo(2);
    }];
    
}
#pragma mark - 数据更新
- (void)setOrderModel:(ZMyOrderListOrderModel *)orderModel{
    if (orderModel) {
        _orderModel = orderModel;
        _lblDate.text = orderModel.createTime;
        _lblName.text = orderModel.user_name;
        _lblPhone.text = orderModel.user_phone;
//        NSMutableArray *arr = [orderModel.user_address componentsSeparatedByString:@" "].mutableCopy;
//        if (arr.count > 3) {
//            [arr removeObjectsInRange:NSMakeRange(0, 3)];
//        }
//        _lblAddress.text = [arr componentsJoinedByString:@" "];
        _lblAddress.text = [orderModel.user_address stringByReplacingOccurrencesOfString:@" " withString:@""];
    }
}
+ (CGFloat)cellHeight{
    return 112;
}


- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
